//    Copyright (C) Clear Office.  All rights reserved.
using System;
using System.Collections.Generic;
using Office.Core.Serialization;
using Office.Spreadsheet.Data;

namespace Office.Spreadsheet.PivotTable
{
    internal class PivotTableMissing : PivotTableValue
    {
        private readonly List<Tuples> _tpls = new List<Tuples>();
        private readonly List<Index> _x = new List<Index>();
        private Boolean _b;
        private string _bc;
        private string _c;
        private UInt32? _cp;
        private Boolean? _f;
        private string _fc;
        private Boolean _i;
        private UInt32? _in;
        private Boolean _st;
        private Boolean? _u;
        private Boolean _un;
        internal const string xmlName = "m";

        #region IOfficeXmlSerializable Members

        public override void ReadXml(ReadContext context)
        {
            using (var c = context.Read(xmlName))
            {
                _u = c.GetOptionalBoolean("u");
                _f = c.GetOptionalBoolean("f");
                _c = c.GetOptionalString("c");
                _cp = c.GetOptionalUInteger("cp");
                _in = c.GetOptionalUInteger("in");
                _bc = c.GetOptionalString("bc");
                _fc = c.GetOptionalString("fc");
                _i = c.GetOptionalBoolean("i", false);
                _un = c.GetOptionalBoolean("un", false);
                _st = c.GetOptionalBoolean("st", false);
                _b = c.GetOptionalBoolean("b", false);
                _tpls.AddRange(c.ReadOptionalWhile<Tuples>("tpls"));
                _x.AddRange(c.ReadOptionalWhile<Index>("x"));
            }
        }

        public override void WriteXml(WriteContext context)
        {
            using (var c = context.Write(xmlName))
            {
                c.SetOptionalBoolean("u", _u);
                c.SetOptionalBoolean("f", _f);
                c.SetOptionalString("c", _c);
                c.SetOptionalUInteger("cp", _cp);
                c.SetOptionalUInteger("in", _in);
                c.SetOptionalString("bc", _bc);
                c.SetOptionalString("fc", _fc);
                c.SetOptionalBoolean("i", _i, false);
                c.SetOptionalBoolean("un", _un, false);
                c.SetOptionalBoolean("st", _st, false);
                c.SetOptionalBoolean("b", _b, false);
                c.WriteElements(_tpls);
                c.WriteElements(_x);
            }
        }

        #endregion
    }
}